<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red;">*</span>角色名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="roleName" lay-verify="title|required" autocomplete="off"
                               placeholder="请输入角色名称"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red;">*</span>角色编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="roleCode" lay-verify="title|required" autocomplete="off"
                               placeholder="请输入角色编码"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="enable" value="true" title="开启" checked>
                        <input type="radio" name="enable" value="false" title="关闭">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label"><span style="color:red;">*</span>类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="roleType" lay-filter="roleType" value="1" title="菜单" checked>
                        <input type="radio" name="roleType" lay-filter="roleType" value="2" title="数据">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入描述" name="details" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="role-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'easyAdmin'], function () {
        let form = layui.form;
        let easyAdmin = layui.easyAdmin;
        let $ = layui.jquery;
        // 获取跳转过来的源头
        var currentTab = easyAdmin.getQueryString("currentTab");
        $('input[name="roleType"][value="' + currentTab + '"]').prop('checked', true); // 设置对应的radio按钮为选中状态

        form.on('submit(role-save)', function (data) {
            easyAdmin.http({
                url: '/sys/role',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("role-table");
                            parent.layui.table.reload("data-role-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>
